package away3d.cameras.lenses ;


import away3d.core.math.Matrix3DUtils ;



/**
 * The PerspectiveLens object provides a projection matrix that projects 3D geometry isometrically. This entails
 * there is no perspective distortion, and lines that are parallel in the scene will remain parallel on the screen.
 */
class OrthographicOffCenterLens extends LensBase
{
    
    
    private var _minX : Float ;
    private var _maxX : Float ;
    private var _minY : Float ;
    private var _maxY : Float ;
    
    
    
    /**
     * Creates a new OrthogonalLens object.
     * @param fieldOfView The vertical field of view of the projection.
     */
    public function new( minX : Float, maxX : Float, minY : Float, maxY : Float )
    {
        
        super() ;
        
        _minX = minX ;
        _maxX = maxX ;
        _minY = minY ;
        _maxY = maxY ;
        
    }
    
    
    public var minX( get_minX, set_minX ) : Float ;
    
    
    private function get_minX() : Float
    {
        
        return _minX ;
        
    }
    
    
    private function set_minX( value : Float ) : Float
    {
        
        _minX = value ;
        invalidateMatrix() ;
        return value ;
        
    }
    
    
    public var maxX( get_maxX, set_maxX ) : Float ;
    
    
    private function get_maxX() : Float
    {
        
        return _maxX ;
        
    }
    
    
    private function set_maxX( value : Float ) : Float
    {
        
        _maxX = value ;
        invalidateMatrix() ;
        return value ;
        
    }
    
    
    public var minY( get_minY, set_minY ) : Float ;
    
    
    private function get_minY() : Float
    {
        
        return _minY ;
        
    }
    
    
    private function set_minY( value : Float ) : Float
    {
        
        _minY = value ;
        invalidateMatrix() ;
        return value ;
        
    }
    
    
    public var maxY( get_maxY, set_maxY ) : Float ;
    
    
    private function get_maxY() : Float
    {
        
        return _maxY ;
        
    }
    
    
    private function set_maxY( value : Float ) : Float
    {
        
        _maxY = value ;
        invalidateMatrix() ;
        return value ;
        
    }
    
    
    /**
     * @inheritDoc
     */
    override private function updateMatrix()
    {
        var raw : Vector<Float> = Matrix3DUtils.RAW_DATA_CONTAINER ;

        raw[ 0  ] = 2/( _maxX-_minX ) ;
        raw[ 5  ] = 2/( _maxY-_minY ) ;
        raw[ 10 ] = 1/( _far-_near ) ;
        raw[ 12 ] = ( _maxX + _minX )/( _minX-_maxX ) ;
        raw[ 13 ] = ( _maxY + _minY )/( _minY-_maxY ) ;
        raw[ 14 ] = _near/( _near-_far ) ;
        raw[ 15 ] = 1 ;
        raw[ 1  ] = raw[ 2 ] = raw[ 3 ] = raw[ 4 ] =
        raw[ 6  ] = raw[ 7 ] = raw[ 8 ] = raw[ 9 ] = raw[ 11 ] = 0 ;
        _matrix.copyRawDataFrom( raw ) ;
        
        _frustumCorners[ 0  ] = _frustumCorners[ 9  ] = _frustumCorners[ 12 ] = _frustumCorners[ 21 ] = _minX ;
        _frustumCorners[ 3  ] = _frustumCorners[ 6  ] = _frustumCorners[ 15 ] = _frustumCorners[ 18 ] = _maxX ;
        _frustumCorners[ 1  ] = _frustumCorners[ 4  ] = _frustumCorners[ 13 ] = _frustumCorners[ 16 ] = _minY ;
        _frustumCorners[ 7  ] = _frustumCorners[ 10 ] = _frustumCorners[ 19 ] = _frustumCorners[ 22 ] = _maxY ;
        _frustumCorners[ 2  ] = _frustumCorners[ 5  ] = _frustumCorners[ 8  ] = _frustumCorners[ 11 ] = _near ;
        _frustumCorners[ 14 ] = _frustumCorners[ 17 ] = _frustumCorners[ 20 ] = _frustumCorners[ 23 ] = _far ;
        
    }
    
    
}